package demo;


import demo.standard.SingletonEager;
import demo.standard.SingletonInnerClass;
import demo.standard.SingletonLazy;

public class ClientForStandard {

    public static void main(String[] args) {
        SingletonEager instanceEager = SingletonEager.getInstance();
        SingletonEager instanceEager2 = SingletonEager.getInstance();
        System.out.println("饿汉式单例1的hashCode:" + instanceEager.hashCode());
        System.out.println("饿汉式单例2的hashCode:" + instanceEager2.hashCode());
        System.out.println("饿汉式单例是否相等:" + (instanceEager.hashCode() == instanceEager2.hashCode()) + "\n");

        SingletonLazy instanceLazy = SingletonLazy.getInstance();
        SingletonLazy instanceLazy2 = SingletonLazy.getInstance();
        System.out.println("懒汉式单例1的hashCode:" + instanceLazy.hashCode());
        System.out.println("懒汉式单例2的hashCode:" + instanceLazy2.hashCode());
        System.out.println("懒汉式单例是否相等:" + (instanceLazy.hashCode() == instanceLazy2.hashCode()) + "\n");


        SingletonInnerClass instanceInnerClass = SingletonInnerClass.getInstance();
        SingletonInnerClass instanceInnerClass2 = SingletonInnerClass.getInstance();
        System.out.println("内部类式单例1的hashCode:" + instanceInnerClass.hashCode());
        System.out.println("内部类单例2的hashCode:" + instanceInnerClass2.hashCode());
        System.out.println("内部类式单例是否相等:" + (instanceInnerClass.hashCode() == instanceInnerClass2.hashCode()));
    }
}
